const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

/**
 * 方法一：
*/


const randomArrFn1 = (arr) => {
    if (!Array.isArray(arr)) return arr
    for (let i = 0; i < arr.length; i++) {
        let index = Math.floor(Math.random() * arr.length)
        let temp = arr[index]
        arr[index] = arr[i]
        arr[i] = temp
    }
    return arr
}


/**
 * 方法二：
*/
const randomArrFn2 = (arr) => {
    if (!Array.isArray(arr)) return arr
    for (let i = 0; i < arr.length; i++) {
        let index = Math.floor(Math.random() * arr.length);
        [arr[i], arr[index]] = [arr[index], arr[i]]
    }
    return arr
}

console.log(randomArrFn1(arr),'randomArrFn1(arr)')
console.log(randomArrFn2(arr),'randomArrFn2')